import request from '@/utils/request'

/**
 *
 * @param {*} params
 * @returns 获取员工列表
 */
const getEmployeeList = (params) => {
  return request({ url: '/sys/user', params })
}

/**
 *
 * @param {*}
 * @returns blob 返回二进制流
 */
const exportEmployee = (data) => {
  return request({ url: '/sys/user/export', responseType: 'blob' })
}

/**
 * 下载员工的导入模板
 * @returns 返回 blob
 */
const getExportTemplate = () => {
  return request({ url: '/sys/user/import/template', responseType: 'blob' })
}

/**
 * 上传用户excel
 */
const uploadExcel = (data) => {
  return request({ url: '/sys/user/import', method: 'post', data /* data的类型为 form-data */ })
}

/**
 * 删除员工
 */
const delEmployee = (id) => {
  return request({
    url: `/sys/user/${id}`,
    method: 'delete'
  })
}

/**
 * 新增员工
 */
const addEmployee = (data) => {
  return request({
    url: '/sys/user',
    method: 'post',
    data
  })
}

/**
 * 获取员工详情
 */
const getEmployeeDetail = (id) => {
  return request({ url: `/sys/user/${id}`, method: 'get' })
}

/**
 * 修改员工信息
 */
const updateEmployee = (data) => {
  return request({ url: `/sys/user/${data.id}`, method: 'put', data })
}

/**
 * 获取可用角色
 */
const getEnableRoleList = (id) => {
  return request({
    url: '/sys/role/list/enabled'
  })
}

/**
 * 分配员工角色
 */
const assignRoles = (data) => {
  request({ url: '/sys/user/assignRoles', method: 'put', data })
}

export {
  getEmployeeList,
  exportEmployee,
  getExportTemplate,
  uploadExcel,
  delEmployee,
  addEmployee,
  getEmployeeDetail,
  updateEmployee,
  getEnableRoleList,
  assignRoles
}
